﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="YUIMenuList.aspx.cs" Inherits="ZX.WebApp.EditWidows.YUIMenuList" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <!--CSS file (default YUI Sam Skin) -->
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/treeview/assets/treeview-core.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/fonts/fonts-min.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <!-- Source files -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <div id="listpage">
        <cc1:TreeViewMenu ID="TreeViewMenu1" runat="server"></cc1:TreeViewMenu>
    </div>
    </form>
</body>
<script type="text/javascript">
    var tree2 = null;
    (function () {
        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;

        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                        { position: 'center', body: 'TreeViewMenu1', gutter: '1 2 1 1', header: '列表', scroll: true}]
            });
            layout.render();
        });
        var makeBranch = function (parent, label) {
        }
        tree2 = new YAHOO.widget.TreeView("TreeViewMenu1");
        makeBranch(tree2.getRoot());
        tree2.setNodesProperty('propagateHighlightUp', true);
        tree2.setNodesProperty('propagateHighlightDown', true);
        tree2.subscribe('clickEvent', tree2.onEventToggleHighlight);
        tree2.render();

        var request = "../Extend/AjaxData/DataProcessin.aspx?action=Get&entity=<%=MasterEntityName %>&condition=<%=conditonId %>";
        YAHOO.util.Connect.asyncRequest('POST', request, {
            success: function (res) {
                var inventory;
                try {
                    var userIDs = [];
                    var str = res.responseText;
                    var items = eval("[" + str + "]");
                    var selectid = "<%=selectId %>";
                    for (var i = 0; i < items[0].rows.length; i++) {
                        switch (selectid) {
                            case "RoleID":
                                userIDs.push(items[0].rows[i].RoleID);
                                break;
                            case "TrSubjectInfoID":
                                userIDs.push(items[0].rows[i].TrSubjectInfoID);
                                break;
                            case "TrCourseID":
                                userIDs.push(items[0].rows[i].TrCourseID);
                                break;
                        }
                    }
                    checkNode(userIDs.join(","));
                    tree2.render();
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("读取菜单数据错误：" + error.statusText);
            }
        }, null);
    })();
    function checkNode(userIDs) {
        var topNodes = tree2.getRoot().children;
        for (var i = 0; i < topNodes.length; ++i) {
            var id = topNodes[i].href.split("#@")[1];
            if (userIDs.indexOf(id) > -1) {
                topNodes[i].highlightState = 1; // setNodesByProperty
                ('highlightState');
            }
        }
    }
    var ids = "";
    var fkey;
    var names = "";
    var flag = "";
    function Native(caption, key) {
        flag = "single"; //标识为单选 
        fkey = key;
        if (ids.indexOf(fkey) == -1) {
            ids = fkey + ",";
            names = caption + ",";
        }
    }
    function Save() {
        var entity = "<%=MasterEntityName %>";
        if (flag == "single") {
            if (entity == "" || entity == "DatDepartment") { //选择部门分公司
                parent._fn("", "");
                ids = ids.substring(0, ids.length - 1);
                names = names.substring(0, names.length - 1);
                parent._fn(ids, names);
            }
        } else {
            var hiLit = tree2.getNodesByProperty('highlightState', 1);
            var labels = [];
            if (YAHOO.lang.isNull(hiLit)) {
                labels.push("null");
            } else {
                for (var i = 0; i < hiLit.length; i++) {
                    var node = tree2.getTreeDefinition();
                    labels.push(hiLit[i].href.split("#@")[1]);
                }
            }
            var url = "../Extend/AjaxData/DataProcessin.aspx?action=Save&entity=<%=MasterEntityName %>&ids=" + labels + "&id=<%=pId %>";
            YAHOO.util.Connect.asyncRequest('POST', url, {
                success: function (res) {
                    var inventory;
                    try {
                        inventory = res.responseText;
                        if (inventory == "1") {
                            alert("保存成功!");
                            parent.closeWin();
                        } else {
                            alert("保存失败!");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("读取菜单数据错误：" + error.statusText);
                }
            }, null);
        }
    }
</script>
</html>
